package procomponent;

import java.io.File;

import com.Const;
/**
 * 定时任务类
 */
public class TimerTask {
	

	/**
     * 递归删除目录下的所有文件及子目录下所有文件
     * @param dir 将要删除的文件目录
     * @return boolean Returns "true" if all deletions were successful.
     *                 If a deletion fails, the method stops attempting to
     *                 delete and returns "false".
     */
	private static boolean deleteDir(File dir) {
        if (dir.isDirectory()) {
            String[] children = dir.list();
            //递归删除目录中的子目录下
            for (int i=0; i<children.length; i++) {
                boolean success = deleteDir(new File(dir, children[i]));
                if (!success) {
                    return false;
                }
            }
        }
        // 目录此时为空，可以删除
        return dir.delete();
    }
    /**
     *测试
     */
    public static void main(String[] args) {
        String file=Const.server_path+"/export_sjsc/";
        String file1=Const.server_path+"/Picture/";
        String file2=Const.server_path+"/plupload/";
        String file3=Const.server_path+"/uploadPic/";
        
        try
        {
        	deleteDir(new File(file));
        	deleteDir(new File(file1));
        	deleteDir(new File(file2));
        	deleteDir(new File(file3));
        	System.out.println("Successfully deleted populated directory: " );
        }catch(Exception f)
        {
        	 System.out.println("Failed to delete populated directory: " );
        }
            
         
    }

}
